package com.nowar.data.frame.context;

import com.nowar.data.entity.context.DataSourceContext;

import java.util.Optional;

/**
 * @Author: 谢无殇。
 * @Date : 2023-01-15 23:48
 */
public class DataSourceThreadLocal {
    private static final ThreadLocal<DataSourceContext> CONTEXT = new ThreadLocal<>();

    public static DataSourceContext get() {
        return Optional.ofNullable(CONTEXT.get()).orElse(new DataSourceContext());
    }

    public static void setDataSourceContext(DataSourceContext context) {
        CONTEXT.set(context);
    }

    public static void remove() {
        CONTEXT.remove();
    }
}
